﻿namespace Web.Control.WWW.Group
{
    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Text.RegularExpressions;
    using System.IO;
    using Lx.Web.Common.ControlsUI;
    using Lx.Web.Common.UI;
    using Model.WWW_WWW.Group;
    using BLF.WWW_WWW.Group;
    using System.Collections.Generic;
    using BLF;

    public class Main : BaseControl
    {
        
        protected Repeater repGroup;
        protected Repeater repTopic;
        protected Repeater repAmem;
        protected Repeater repMemberno;
        /// <summary>
        /// 组的ID
        /// </summary>
        protected string gid="";
        /// <summary>
        /// 浏览者的会员号
        /// </summary>
        protected string Memberno = "";
        /// <summary>
        /// 最近的10个帖子
        /// </summary>
        protected List<TopicModel> tmList;
        /// <summary>
        /// 相关的5个组
        /// </summary>
        protected List<GroupModel> gmList;
        /// <summary>
        /// 组的TAG
        /// </summary>
        protected List<string> tagList;
        /// <summary>
        /// 组的管理员
        /// </summary>
        protected List<MemberModel> amList;
        /// <summary>
        /// 组的最近加入的6个会员
        /// </summary>
        protected List<MemberModel> mmList;
        /// <summary>
        /// 组的详细信息
        /// </summary>
        protected GroupModel gm;
        ArrayList al = new ArrayList();
        /// <summary>
        /// 当不为空的时候表示刚刚创建成功的组。
        /// </summary>
        protected string ct = "";
        /// <summary>
        /// 登陆人名称
        /// </summary>
        protected string NickName = "";
        protected override void OnLoad(EventArgs e)
        {

            if (!string.IsNullOrEmpty(Request["gid"]) && Request["gid"] != "")
            {
                gid = Request["gid"].ToString();
                if (!string.IsNullOrEmpty(Request["ct"]))
                {
                    ct = Request["ct"];
                }
                if (HttpContext.Current.User.Identity.Name != "")
                {
                    Memberno = HttpContext.Current.User.Identity.Name;
                }
                if (!string.IsNullOrEmpty(Request.Form["Rety"]) && Request.Form["Rety"] == "join")
                {
                    al = BLF.WWW_WWW.Group.Group.GetAGroup(Int64.Parse(gid), Memberno, "1");
                }
                else
                {
                    al = BLF.WWW_WWW.Group.Group.GetAGroup(Int64.Parse(gid), Memberno);
                }
                gm = al[0] as GroupModel;
                tagList = al[1] as List<string>;
                amList = al[2] as List<MemberModel>;
                mmList = al[3] as List<MemberModel>;
                gmList = al[4] as List<GroupModel>;
                tmList = al[5] as List<TopicModel>;
                NickName = al[6].ToString();
                if (repGroup != null)
                {
                    repGroup.DataSource = gmList;
                    repGroup.DataBind();
                }
                if (repTopic != null)
                {
                    repTopic.DataSource = tmList;
                    repTopic.DataBind();
                }
                if (repAmem != null)
                {
                    repAmem.DataSource = amList;
                    repAmem.DataBind();
                }
                if (repMemberno != null)
                {
                    repMemberno.DataSource = mmList;
                    repMemberno.DataBind();
                }
                //标题
                string tags = "";
                for (int i = tagList.Count - 1; i >= 0; i--)
                {
                    tags += tagList[i] + ", ";
                }
                string gType = "";
                switch (gm.GroupType)
                {
                    case "1":
                        gType = GetText("GP013");
                        break;
                    case "2":
                        gType = GetText("CT011");
                        break;
                    case "3":
                        gType = GetText("C0087");
                        break;
                }                
                this.DynamicTitle = GetText("GP510", new string[] { gm.Title });
                if (gm.Language1 != "")
                {
                    this.DynamicKeywords = GetText("GP511", new string[] { gType, tags, BLF.StaticData.GetLanguageText(gm.Language1), BLF.StaticData.GetLanguageText(gm.Language2) });
                }
                else
                {
                    this.DynamicKeywords = GetText("GP558", new string[] { gType, tags, BLF.StaticData.GetLanguageText(gm.Language2) });
                    
                }
                this.DynamicDescription = GetText("GP512", new string[] { HttpUtility.HtmlAttributeEncode(Lx.Web.Common.UI.Globals.GetString(gm.Desc, 160)) });
                base.OnLoad(e);
            }
            else
            {
                Response.End();
                return;
            }
        }

    }
}